﻿Imports FinanceiroBLL
Imports FinanceiroDAL  'BLL do Sub Grupo
Public Class CentroCustoFRM
    Dim objBLL As New CentroCustoBLL
    Public Op As String
    Public codigo As Integer
    Private Sub CentroCustoFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        objconexao.carregaCombo(CBTipo, "Financeiro.Gen_Grupos", "gru_codigo", "gru_descricao", "", "")
        CBTipo.SelectedValue = 1
        Limpar()
        If (Op = "I") Then
            LBCodigo.Visible = False
            LCentroCusto.Text = "Centro Custo"
            LBCodigo.Text = 0
        Else
            LBCodigo.Visible = True
            CarregaCampos(codigo)
        End If
    End Sub
#Region "Salvar / Alterar"
    Private Sub TSBSalvar_Click(sender As System.Object, e As System.EventArgs) Handles TSBSalvar.Click
        Try

            objBLL = New CentroCustoBLL(codigo, CBTipo.SelectedValue, StrConv(Trim(TBDescricao.Text), VbStrConv.ProperCase))
            If Op = "I" Then
                objBLL.Inserir()
                MessageBox.Show("Centro Custo inserido com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Limpar()
                Me.Close()
            Else
                objBLL.Alterar()
                MessageBox.Show("Centro Custo alterada com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Limpar()
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
            TBDescricao.Focus()

        End Try
    End Sub
#End Region
#Region "Limpar campos"
    Sub Limpar()
        CBTipo.SelectedValue = 1
        TBDescricao.Text = ""
        Me.objBLL = Nothing
    End Sub
#End Region
#Region "Carrega Campos"
    Sub CarregaCampos(codigo As Integer)
        objBLL = New CentroCustoBLL(codigo)
        LBCodigo.Text = "Código: " & objBLL.subcodigo
        LCentroCusto.Text = objBLL.subnome
        TBDescricao.Text = Trim(objBLL.subnome)
        CBTipo.SelectedValue = objBLL.codgrupo
    End Sub
#End Region
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Me.Close()
        objBLL = Nothing
    End Sub
#Region "Carrega grid"
    Sub CarregaGrid()
        objBLL = New CentroCustoBLL
        DGVDados.DataSource = objBLL.buscar("", 4)
        DGVDados.Refresh()
    End Sub
#End Region

#Region "Cor de fundo do datagridview"
    Private Sub DGVDados_RowPrePaint(sender As System.Object, e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DGVDados.RowPrePaint
        If DGVDados.Rows(e.RowIndex).Index Mod (2) = 1 Then
            DGVDados.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Gainsboro
        End If
    End Sub
#End Region
End Class